home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * dh.c
- *
- * this code puts up a window with 3 buttons. with these buttons,
- * you can create X or GL windows. if the envrionmental variable
- * ALT_DISPLAY is set, you can create the windows on another display
- */
-
- #include <stdio.h>
- #include <device.h>
- #include <math.h>
- #include <X11/Intrinsic.h>
- #include <X11/IntrinsicP.h>
- #include <X11/CoreP.h>
- #include <X11/Xirisw/GlxMDraw.h>
- #include <X11/Shell.h>
- #include <Xm/BulletinB.h>
- #include <Xm/Form.h>
- #include <Xm/RowColumn.h>
- #include <Xm/PushB.h>
-
- #include <gl/glws.h>
-
-
- /*
- * GLXconfig for a doublebuffered, RGB gl drawing area
- */
- static GLXconfig view_glxconfig [] = {
- { GLX_NORMAL, GLX_DOUBLE, TRUE },
- { GLX_NORMAL, GLX_RGB, TRUE },
- { GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG },
- { 0, 0, 0 }
- };
-
- /*
- * some colors
- */
- #define COLOR1 0x00FF1111
- #define COLOR2 0x000000FF
-
- /*
- * some X colors
- */
- int WHITE_PIXEL_NUM;
- int BLACK_PIXEL_NUM;
-
- /*
- * global X stuff
- */
-
- Widget toplevel, toplevel2, toplevel3;
-
- /*
- * X display structure pointers;
- */
- Display *main_display; /* display #1, the main display */
- Display *alt_display ; /* display #2, the alternate display */
- Display *current_display; /* the current display */
-
- XtAppContext appContext; /* X application context */
-
- long curr_color; /* current selected gl color */
- int curr_X_color; /* current selected X color */
-
-
- /*
- * some callback functions
- */
- void initGl1();
- void newGL();
- void newX();
- void switchS();
-
- /*
- * main routine
- */
- main(argc, argv)
- int argc;
- char *argv[];
- {
-
- /*
- * local variables
- */
- Arg args[10];
- Cardinal n;
- int i = 0;
- Widget f1, f2, f3;
- Widget b1, b2, b3;
-
- char *screen1, *screen2;
- char *alternate_display;
-
-
- /*
- * initialize toolkit, open display
- */
- XtToolkitInitialize();
- appContext = XtCreateApplicationContext();
- main_display = XtOpenDisplay(appContext, ":0.0", NULL, "Explore",
- NULL, 0, &argc, argv);
- if (!main_display) {
- printf("\n can't open display");
- exit(1);
- }
-
-
- /*
- * create a top level shell to hold the control buttons
- */
- n = 0;
- toplevel = XtAppCreateShell(NULL, "dh",
- applicationShellWidgetClass, main_display, NULL, 0);
-
- n = 0;
- XtSetArg(args[n], XmNheight, 200); n++;
- XtSetArg(args[n], XmNwidth, 100); n++;
- f1 = XmCreateRowColumn(toplevel, "form", args, n);
- XtManageChild(f1);
-
- n = 0;
- b1 = XmCreatePushButton(f1, "newGL", args, n);
- XtManageChild(b1);
- XtAddCallback(b1, XmNactivateCallback, newGL, 0);
-
- n = 0;
- b2 = XmCreatePushButton(f1, "newX", args, n);
- XtManageChild(b2);
- XtAddCallback(b2, XmNactivateCallback, newX, 0);
-
- n = 0;
- b3 = XmCreatePushButton(f1, "switch screen", args, n);
- XtManageChild(b3);
- XtAddCallback(b3, XmNactivateCallback, switchS, 0);
-
- XtRealizeWidget(toplevel);
-
- /*
- * now get the ALT_DISPLAY environment variable. if it is not set,
- * display a message and run the alternate display on the same screen
- * as the main display
- */
- alternate_display = (char *) getenv("ALT_DISPLAY");
-
- if (alternate_display == NULL)
- fprintf(stderr, "\nALT_DISPLAY not set, running single display\n");
-
- if ((alt_display = XtOpenDisplay(appContext, alternate_display, NULL, "Explore",
- NULL, 0, &argc, argv)) == NULL) {
- printf("\n can't open second display, running single...");
- fflush(stdout);
- alt_display = main_display;
- }
-
- /*
- * set the current display and current color
- */
- current_display = alt_display ;
- curr_color = COLOR2;
-
- /*
- * get the white pixel value for the main display
- */
- WHITE_PIXEL_NUM = WhitePixel(main_display, 0);
-
- /*
- * get the black pixel value for the alternate display
- */
- BLACK_PIXEL_NUM = BlackPixel(alt_display, 0);
-
- curr_X_color = BLACK_PIXEL_NUM;
-
- /*
- * X main loop
- */
- XtAppMainLoop(appContext);
-
- }
-
-
- /*
- * callback routine to initialize a GL window; it just
- * clears the gl drawing area with the current color
- */
- void initGl1(w, calldata, clientdata)
-
- Widget w;
- char *calldata, *clientdata;
- {
-
- GLXwinset(XtDisplay(w), XtWindow(w));
-
- cpack(curr_color);
- clear();
- swapbuffers();
- }
-
-
- /*
- * callback for the new GL button. it creates a new shell
- * with a gl drawing area in it. the shell is created on the
- * current display, via the "current_display" argument int the
- * XtAppCreateShell() call
- */
- void newGL(w, calldata, clientdata)
-
- Widget w;
- char *calldata, clientdata;
- {
-
- Widget top, gl;
- int n;
- Arg args[10];
- XmString xmstr;
- char window_name[128];
-
- /*
- * we will set the window name to be:
- * "newGL <display name>"
- * so for screen :0.0 it would be:
- * "newGL :0.0"
- * we can get the display name from the XDisplay structure member
- * "display_name"
- */
- memset(window_name, 0, 128);
- strcpy(window_name, "newGL ");
- strcat(window_name, DisplayString(current_display));
-
- /*
- * creat the new shell window
- */
- n = 0;
- top = XtAppCreateShell(window_name, "newGL",
- applicationShellWidgetClass, current_display, NULL, 0);
-
- /*
- * create the gl drawing area, add appropriate callbacks
- */
- n = 0;
- XtSetArg(args[n], XmNheight, 200); n++;
- XtSetArg(args[n], XmNwidth, 200); n++;
- XtSetArg(args[n], GlxNglxConfig, view_glxconfig); n++;
- gl = GlxCreateMDraw(top, "view", args, n);
- XtManageChild(gl);
- XtAddCallback(gl, GlxNginitCallback, (XtCallbackProc)initGl1, NULL);
- XtAddCallback(gl, GlxNexposeCallback, (XtCallbackProc)initGl1, NULL);
-
- /*
- * realize widget
- */
- XtRealizeWidget(top);
-
- }
-
-
- /*
- * callback for the new X button. it creates a new application shell
- * with a row/column widget in it. the shell is created on the
- * current display, via the "current_display" argument int the
- * XtAppCreateShell() call
- */
- void newX(w, calld, clientd)
-
- Widget w;
- char *calld, *clientd;
-
- {
- Widget top, f;
- int n;
- Arg args[10];
- char window_name[128];
-
- /*
- * we will set the window name to be:
- * "newX <display name>"
- * so for screen :0.0 it would be:
- * "newX :0.0"
- * we can get the display name from the XDisplay structure member
- * "display_name"
- */
- memset(window_name, 0, 128);
- strcpy(window_name, "newX ");
- strcat(window_name, DisplayString(current_display));
-
- /*
- * create the new shell
- */
- n = 0;
- XtSetArg(args[n], XmNheight, 200); n++;
- XtSetArg(args[n], XmNwidth, 200); n++;
- XtSetArg(args[n], XmNbackground, curr_X_color); n++;
- top = XtAppCreateShell(window_name, "newX",
- applicationShellWidgetClass, current_display, args, n);
-
- /*
- * realize the widget
- */
- XtRealizeWidget(top);
- }
-
-
- /*
- * switch display button callback. it toggles between displays and
- * the current gl fill color
- */
- void switchS(w, calld, clid)
-
- Widget w;
- char *calld, clid;
- {
-
- /*
- * if the current display is the main display, main_display,
- * switch to the alternate display, alt_display , and switch colors
- */
- if (current_display == main_display) {
- current_display = alt_display ;
- curr_color = COLOR2;
- curr_X_color = BLACK_PIXEL_NUM;
- }
- else {
-
- /*
- * alternate display is current, so switch back to the main
- * display, main_display, and switch colors
- */
- current_display = main_display;
- curr_color = COLOR1;
- curr_X_color = WHITE_PIXEL_NUM;
- }
- }
-